using System.IO;
using System.Windows.Media.Imaging;

namespace SalesPoint.Converters
{
  public static class BitmapImageConverter
  {
    public static BitmapImage ConvertToBitmap(byte[] bytes)
    {
      var bi = new BitmapImage();
      bi.BeginInit();
      bi.CacheOption = BitmapCacheOption.OnLoad;
      bi.DecodePixelWidth = 30;
      using (var stream = new MemoryStream()) {
        // Well-known work-around to make Northwind images work
        stream.Write(bytes, 78, bytes.Length - 78);
        bi.StreamSource = stream;
        bi.EndInit();
      }
      return bi;
    }
  }
}
